using MidnightPeach.Engine.Packages;
using MidnightPeach.Engine.Schema;
using MidnightPeach.Engine.Schema.DataSchema;

namespace MidnightPeach.Engine.Generators.DataGenerators
{
    internal class TableGenerator : DataGenerator
    {
        private readonly Table _table;

        public TableGenerator(Package package, Table table) : base(package)
        {
            _table = table;
        }

        internal override string Generate(Macro macro, string text)
        {
            switch (macro.Value)
            {
                case "Name":
                    return _table.Name;

                case "PascalName":
                    return _table.PascalName;

                case "CamelName":
                    return _table.CamelName;

                case "BeginCommentIfView":
                    return _table.TableType == TableType.Table ? string.Empty : "/* not available for view";

                case "EndCommentIfView":
                    return _table.TableType == TableType.Table ? string.Empty : "*/";

                case "CommaIfHasInc":
                    return _table.HasIncrementalColumn() ? "," : string.Empty;

                case "BeginCommentIfMapping":
                    return _table.IsMappingTable() ? "/* not available for mapping table that has only two columns." : string.Empty;

                case "EndCommentIfMapping":
                    return _table.IsMappingTable() ? "not available for mapping table that has only two columns. */" : string.Empty;

                case "BeginCommentOnNoneFK":
                    return _table.HasForeignKey() == false ? "/* not available for table that has no foreign key" : string.Empty;

                case "EndCommentOnNoneFK":
                    return _table.HasForeignKey() == false ? "not available for table that has no foreign key */" : string.Empty;

                case "Identifier":
                    return _table.Identifier;

                default:
                    throw new UnsupportedMacroException(macro, text, this);
            }
        }
    }
}